﻿using TraumaCenterSystem.Core;
using TraumaCenterSystem.TraumaCenterManage;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TraumaCenterSystem.Bll
{
    /// <summary>
    /// 患者管理类
    /// </summary>
    public class PatientManager : BaseManager
    {
        /// <summary>
        /// 新增和编辑患者总览
        /// </summary>
        /// <returns></returns>
        public static OperateResult SetPatientOverview(string oiverviewJson)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                TraumaCenterManageSoapClient service = new TraumaCenterManageSoapClient();
                ResultHelperOfBoolean result = service.SetPatientOverview(oiverviewJson);
                if (result.S)
                {
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 患者总览
        /// </summary>
        /// <returns></returns>
        public static OperateResult GetPatientOverview(int pageIndex, int pageSize, string patientName, int patientStatus, int pathWayId, int arrivedType, string PatientId)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                TraumaCenterManageSoapClient service = new TraumaCenterManageSoapClient();
                ResultHelperOfString result = service.GetPatientOverview(patientName, patientStatus, pathWayId, -1, arrivedType, pageIndex, pageSize,PatientId);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }


        /// <summary>
        /// 获取当前急救人列表 
        /// </summary>
        /// <returns></returns>
        public static OperateResult GetPatientList()
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                TraumaCenterManageSoapClient service = new TraumaCenterManageSoapClient();
                ResultHelperOfString result = service.GetPatientList();
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }

        /// <summary>
        /// 获取病人信息明细
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public static OperateResult GetPatientDetail(string patientId)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                TraumaCenterManageSoapClient service = new TraumaCenterManageSoapClient();
                ResultHelperOfString result = service.GetPatientDetail(patientId);
                if (result.S)
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }

            return resultInfo;
        }
        /// <summary>
        /// 删除当前急救人列表 作废
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public static OperateResult DeletePatientRecord(string patientId)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                TraumaCenterManageSoapClient service = new TraumaCenterManageSoapClient();
                ResultHelperOfBoolean result = service.DeletePatientRecord(patientId);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = -1;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
    }
}